IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[t_subject]') AND type in (N'U'))
DROP TABLE [dbo].[t_subject]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[t_subject_channel]') AND type in (N'U'))
DROP TABLE [dbo].[t_subject_channel]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[t_news]') AND type in (N'U'))
DROP TABLE [dbo].[t_news]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[t_news_channel]') AND type in (N'U'))
DROP TABLE [dbo].[t_news_channel]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[t_nser]') AND type in (N'U'))
DROP TABLE [dbo].[t_nser]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[t_user_group]') AND type in (N'U'))
DROP TABLE [dbo].[t_user_group]
GO

---------------------------------------------------------------------------------------------------------------
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[t_subject]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[t_subject](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[name] [nvarchar](50) NOT NULL,
	[keywords] [nvarchar](200) NOT NULL,
	[url] [nvarchar](200),
	[image] [nvarchar](200),
	[des] [nvarchar](3000) NOT NULL,
	[time_add] [datetime] NOT NULL,
	[weight] [tinyint] NOT NULL ,
	[state] [tinyint]
	
	PRIMARY KEY CLUSTERED 
	(
		[id] ASC
	)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]	
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[t_subject_channel]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[t_subject_channel](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[subject_id] [int] NOT NULL,
	[name] [nvarchar](200) NOT NULL,
	[keywords] [nvarchar](200),
	[show_name] [nvarchar](50),
	[state] [tinyint] NOT NULL DEFAULT 0,
	[weight] [tinyint] ,
	[image] [nvarchar](200)

	PRIMARY KEY CLUSTERED 
	(
		[id] ASC
	)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]	
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[t_news]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[t_news](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[state] [tinyint] NOT NULL,
	[channel_id] [int] NOT NULL,
	[title] [nvarchar](100) NOT NULL,
	[second_title] [nvarchar](100),
	[digest] [nvarchar](200),
	[content] [ntext],
	[img_home] [nvarchar](100),
	[tags] [nvarchar](100),
	[adder] [nvarchar](50),
	[publisher] [nvarchar](50),
	[editor] [nvarchar](50),
	[time_add] [datetime] DEFAULT GETDATE(),
	[time_pub] [datetime] DEFAULT GETDATE(),
	[time_edit] [datetime] DEFAULT GETDATE(),
	[source] [nvarchar](50),
	[click_counter] [int] NOT NULL DEFAULT 0,
	[recommend] [nvarchar](200),
	[weight] [tinyint] NOT NULL DEFAULT 0,
	[comment_counter] [int] NOT NULL DEFAULT 0,
	[comment_enabeld] [bit] DEFAULT 0
	

	PRIMARY KEY CLUSTERED 
	(
		[id] ASC
	)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]	
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[t_news_channel]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[t_news_channel](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[parent_id] [int] NOT NULL,
	[depth] [int] NOT NULL,
	[name] [nvarchar](50),
	[weight] [int],
	[comment_enabled] [bit] NOT NULL DEFAULT 0,

	PRIMARY KEY CLUSTERED 
	(
		[id] ASC
	)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]	
) ON [PRIMARY]
END
GO


SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[t_user]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[t_user](
	[name] [nvarchar](50) NOT NULL PRIMARY KEY ,
	[fullname] [nvarchar](50) NOT NULL,
	[pwd] [nvarchar](100) NOT NULL,
	[status] [tinyint] NOT NULL,
	[group_id] [int],
	[state] [tinyint],
	[email] [nvarchar](50),
	[tel] [nvarchar](50),
	[dept] [nvarchar](50),
	[time_lastlog] [nvarchar](50),
	[last_ip] [datetime],
	[log_counter] [int],
	[news_added] [int],
	[des] [nvarchar](200)	

) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[t_user_group]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[t_user_group](
	[id] [int] IDENTITY(1,1) NOT NULL PRIMARY KEY,
	[name] [nvarchar](50) NOT NULL,
	[rights] [nvarchar](4000) NOT NULL
	
) ON [PRIMARY]
END
GO
